<template>
  <Layout>
    <div style="min-height: 600px">
      <div v-if="projects && projects.length > 0">
        <el-card
          shadow="hover"
          v-for="pro in projects"
          :key="pro.node.id"
          style="margin-bottom: 20px"
        >
          <div slot="header">
            <el-row>
              <el-col :span="16">
                <span>
                  <g-link
                    :to="`/project/detail/${pro.node.id}`"
                    style="text-decoration:none;cursor:pointer"
                  >
                    <i class="el-icon-service"></i>&nbsp;&nbsp;
                    {{ pro.node.name }}
                  </g-link>
                </span>
              </el-col>
              <el-col :span="8">
                <div style="text-align: right;">
                  <el-button
                    @click="toGithub(pro.node.url)"
                    style="padding: 3px 0"
                    type="text"
                    icon="el-icon-back"
                  >
                    前往Github
                  </el-button>
                  <el-button
                    style="padding: 3px 0"
                    type="text"
                    icon="el-icon-share"
                  ></el-button>
                </div>
              </el-col>
            </el-row>
          </div>
          <div style="font-size: 0.9rem;line-height: 1.5;color: #606c71;">
            最近更新 {{ pro.node.updateTime | date }}
          </div>
          <div
            style="font-size: 1.1rem;line-height: 1.5;color: #303133;padding: 10px 0px 0px 0px"
          >
            {{ pro.node.description || 'Ta 很懒，什么也没留下' }}
          </div>
          <div
            style="font-size: 1.1rem;color: #303133;padding: 10px 0px 0px 0px"
          >
            <el-row>
              <el-col :span="16" style="padding-top: 5px">
                <el-tooltip
                  effect="dark"
                  :content="'star ' + pro.node.stargazersCount"
                  placement="bottom"
                >
                  <i
                    class="el-icon-star-off"
                    style="margin: 0px 5px 0px 0px"
                  ></i>
                </el-tooltip>
                {{ pro.node.stargazersCount }}
                <el-tooltip
                  effect="dark"
                  :content="'watch ' + pro.node.watchersCount"
                  placement="bottom"
                >
                  <i class="el-icon-view" style="margin: 0px 5px 0px 15px"></i>
                </el-tooltip>
                {{ pro.node.watchersCount }}
                <el-tooltip
                  effect="dark"
                  :content="'fork ' + pro.node.forksCount"
                  placement="bottom"
                >
                  <i class="el-icon-bell" style="margin: 0px 5px 0px 15px"></i>
                </el-tooltip>
                {{ pro.node.forksCount }}
              </el-col>
              <el-col :span="8" style="text-align: right;">
                <el-tag
                  class="tag"
                  size="small"
                  type="danger"
                  v-if="pro.node.license"
                >
                  {{ pro.node.license }}
                </el-tag>
                <el-tag class="tag" size="small" type="success">
                  {{ pro.node.language }}
                </el-tag>
              </el-col>
            </el-row>
          </div>
        </el-card>
      </div>

      <el-card
        shadow="never"
        style="margin-bottom: 20px;padding: 20px 0px 20px 0px;text-align: center"
        v-if="!projects || projects.length == 0"
      >
        <font style="font-size: 30px;color:#dddddd ">
          <b>还没有开源项目 (╯°Д°)╯︵ ┻━┻</b>
        </font>
      </el-card>
    </div>
  </Layout>
</template>

<page-query>
query {
	allProject {
    edges {
      node {
        id
        name
        description
        updateTime
        stargazersCount
        watchersCount
        forksCount
        url
        language
        license
      }
    }
  }
}
</page-query>

<script>
export default {
  name: 'ProjectPage',
  metaInfo: {
    title: '开源项目'
  },
  computed: {
    projects () {
      return this.$page.allProject.edges
    }
  },
  methods: {
    toGithub (url) {
      window.open(url, '_blank')
    }
  }
}
</script>

<style></style>
